<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="订单号">
              <a-input placeholder="请输入订单号" v-model="queryParam.orderNum"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="订单创建时间">
              <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.payTime_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.payTime_end"></j-date>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="商品名称">
                <a-input placeholder="商品名称" v-model="queryParam.goodname"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="用户id">
                <a-input placeholder="用户id" v-model="queryParam.userId"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="用户名">
                <a-input placeholder="用户名" v-model="queryParam.username"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="手机号">
                <a-input placeholder="手机号" v-model="queryParam.phone"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('订单')">导出</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="gotoPage(record)">序列号</a>
        </span>

        <span slot="termId" slot-scope="text, record, index">
            <a-tag color="pink" v-if="text==31">1个月</a-tag>
            <a-tag color="red" v-if="text==93" >3个月</a-tag>
           <a-tag color="orange" v-if="text==186" >6个月</a-tag>
           <a-tag color="green" v-if="text==366" >1年</a-tag>
           <a-tag color="cyan" v-if="text==732" >2年</a-tag>
           <a-tag color="blue" v-if="text==1098" >3年</a-tag>
        </span>

        <span slot="status" slot-scope="text, record, index">
            <a-tag color="blue" v-if="text==0">待支付</a-tag>
            <a-tag color="#87d068" v-if="text==1" >已支付</a-tag>
           <a-tag color="red" v-if="text==2" >已放弃</a-tag>
        </span>
      </a-table>
    </div>

    <userhome-order-modal ref="modalForm" @ok="modalFormOk"></userhome-order-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import UserhomeOrderModal from './modules/UserhomeOrderModal'

  export default {
    name: 'UserhomeOrderList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      UserhomeOrderModal,
    },
    data () {
      return {
        description: '订单管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'订单号',
            align:"center",
            dataIndex: 'orderNum'
          },
          {
            title:'商品名',
            align:"center",
            dataIndex: 'goodname'
          },
          {
            title:'单价(元)',
            align:"center",
            dataIndex: 'uniPrice'
          },
          {
            title:'总数量(件)',
            align:"center",
            dataIndex: 'num'
          },
          {
            title:'有效期',
            align:"center",
            dataIndex: 'termId',
            scopedSlots: { customRender: 'termId' }
          },
          {
            title:'订单总价(元)',
            align:"center",
            dataIndex: 'tprice'
          },
          {
            title:'订单创建时间',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title:'订单支付时间',
            align:"center",
            dataIndex: 'payTime'
          },
          {
            title:'用户id',
            align:"center",
            dataIndex: 'userId'
          },
          {
            title:'用户名',
            align:"center",
            dataIndex: 'username'
          },
          {
            title:'用户手机号码',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'订单状态',
            align:"center",
            dataIndex: 'status',
            scopedSlots: { customRender: 'status' }
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/gongqiang/userhomeOrder/list",
          delete: "/gongqiang/userhomeOrder/delete",
          deleteBatch: "/gongqiang/userhomeOrder/deleteBatch",
          exportXlsUrl: "/gongqiang/userhomeOrder/exportXls",
          importExcelUrl: "gongqiang/userhomeOrder/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      gotoPage(record)
      {
        this.$router.push({
          path: '/igood/serialNumberList',
          query: { orderNum: record.orderNum }
        });
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'orderNum',text:'订单号',dictCode:''})
        fieldList.push({type:'string',value:'goodId',text:'商品id',dictCode:''})
        fieldList.push({type:'string',value:'goodDetailId',text:'商品详情id',dictCode:''})
        fieldList.push({type:'int',value:'num',text:'总数量',dictCode:''})
        fieldList.push({type:'double',value:'tprice',text:'总价',dictCode:''})
        fieldList.push({type:'int',value:'userId',text:'用户id',dictCode:''})
        fieldList.push({type:'datetime',value:'payTime',text:'订单创建时间'})
        fieldList.push({type:'int',value:'status',text:'订单状态',dictCode:''})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>